//
//  AddGoodsViewController.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/24.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "AddGoodsViewController.h"
#import "AddPictureView.h"
#import "WeekButton.h"
#import "PGDatePickManager.h"
#import <CoreFoundation/CoreFoundation.h>
//#import <WebKit/WebKit.h>

@interface AddGoodsViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate,AddPictureViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate,PGDatePickerDelegate,UIWebViewDelegate>{
    
    UIImagePickerController *_imagePickerController;
    NSInteger _typeIndex;
    NSString *_htmlString;//保存输出的富文本
    NSMutableArray *_imageArr;//保存添加的图片
}

@property (nonatomic, assign)NSInteger count;
@property (nonatomic, strong)AddPictureView * addview;
@property (nonatomic, strong)UIAlertController * alertVC;

@property (nonatomic, weak)UIScrollView * scrollView;
@property (nonatomic, weak)UIView * container;

@property (nonatomic, strong)UIImageView * titleImageView;
@property (nonatomic, strong)UIImageView * moneyImageView;
@property (nonatomic, strong)UIImageView * orignImageView;
//@property (nonatomic, strong)UIImageView * telImageView;
@property (nonatomic, strong)UIImageView * localImageView;
@property (nonatomic, strong)UIImageView * openTimeImageView;
@property (nonatomic, strong)UIImageView * vailImageView;
@property (nonatomic, strong)UIImageView * sellImageView;
@property (nonatomic, strong)UIImageView * exploreImageView;
@property (nonatomic, strong)UIImageView * timeImageView;

@property (nonatomic, strong)UILabel * titleNameLabel;
@property (nonatomic, strong)UILabel * priceLabel;
@property (nonatomic, strong)UILabel * orignLabel;
//@property (nonatomic, strong)UILabel * telLabel;
@property (nonatomic, strong)UILabel * localLabel;
@property (nonatomic, strong)UILabel * openLabel;
@property (nonatomic, strong)UILabel * vailLabel;
@property (nonatomic, strong)UILabel * sellLabel;

@property (nonatomic, strong)UITextField * titleTextField;
@property (nonatomic, strong)UITextField * priceTextField;
@property (nonatomic, strong)UITextField * orignTextField;
//@property (nonatomic, strong)UITextField * telTextField;

@property (nonatomic, weak)UIButton * localButton;
@property (nonatomic, strong)UIButton * normalButton;
@property (nonatomic, strong)UIButton * tuanButton;

@property (nonatomic, weak)UIView * modeView;
@property (nonatomic, weak)UIView * normalView;
@property (nonatomic, weak)UIView * normalWeekView;
@property (nonatomic, strong)UILabel * validTimeLabel;
@property (nonatomic, strong)UIButton * normalTimeStartButton;
@property (nonatomic, strong)UIButton * normalTimeEndButton;
@property (nonatomic, strong)UILabel * validDateLabel;
@property (nonatomic, strong)UIButton * normalDateStartButton;
@property (nonatomic, strong)UIButton * normalDateEndButton;
@property (nonatomic, strong)UILabel * oneToLabel;
@property (nonatomic, strong)UILabel * twoToLabel;
@property (nonatomic, strong)UILabel * earlyLabel;
@property (nonatomic, strong)UILabel * hourLabel;
@property (nonatomic, strong)UILabel * repertoryLabel;
@property (nonatomic, strong)UITextField * repertoryTextfield;

@property (nonatomic, weak)UIView * tuanView;
@property (nonatomic, weak)UIView * tuanWeekView;
@property (nonatomic, strong)UILabel * tuanDateLabel;
@property (nonatomic, strong)UILabel * tuanTimeLabel;
@property (nonatomic, strong)UILabel * numPeopleLabel;
@property (nonatomic, strong)UILabel * stopTimeLabel;
@property (nonatomic, strong)UITextField * minPeopleButton;
@property (nonatomic, strong)UITextField * maxPeopleButton;
@property (nonatomic, strong)UILabel * threeToLabel;
@property (nonatomic, strong)UIButton * oneStartButton;
@property (nonatomic, strong)UIButton * twoStartButton;
@property (nonatomic, strong)UIButton * threeStartButton;
@property (nonatomic, strong)UIButton * fourStartButton;
@property (nonatomic, strong)UIButton * fiveStartButton;
@property (nonatomic, weak)UIButton * addButton;
@property (nonatomic, weak)UIButton * subtractButton;
@property (nonatomic, strong)UILabel * cancleLabel;
@property (nonatomic, strong)UILabel * cancleEarlyLabel;
@property (nonatomic, strong)UILabel * earlyHourLabel;
@property (nonatomic, strong)UITextField * stopTimeTextfield;
@property (nonatomic, strong)UITextField * cancleTimeTextfield;
@property (nonatomic, assign)int addCount;

@property (nonatomic, weak)UIView * testView;
@property (nonatomic, weak)UITextView * infoTextView;

@property (nonatomic, strong)UIView * oneLineView;
@property (nonatomic, strong)UIView * twoLineView;
@property (nonatomic, strong)UIView * threeLineView;
@property (nonatomic, strong)UIView * fourLineView;
@property (nonatomic, strong)UIView * fiveLineView;
@property (nonatomic, strong)UIView * sixLineView;

@property (nonatomic, copy)NSString * type;
@property (nonatomic, copy)NSString * typeid;
@property (nonatomic, strong)NSArray * dataArray;
@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)UIPickerView * pickerView;
@property (nonatomic, strong)NSMutableArray * imgArray;

@property (nonatomic, copy)NSString * dateStr;
@property (nonatomic, strong)NSMutableArray * buttonArray;
@property (nonatomic, strong)NSMutableArray * normalButtonArray;

@property (nonatomic, strong)UIWebView * webView;
@property (nonatomic, weak)UIButton * addPictureButton;
@property (nonatomic, copy)NSString * test;
@property (nonatomic, copy)NSString * url;

@property (nonatomic, strong)WeekButton * workButton;
@property (nonatomic, strong)WeekButton * weekendsButton;
@property (nonatomic, strong)WeekButton * everydayButton;

@end

@implementation AddGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.addCount = 1;
    _typeIndex = 0;
    self.imgArray = [NSMutableArray array];
    self.buttonArray = [NSMutableArray array];
    self.normalButtonArray = [NSMutableArray array];
    self.view.backgroundColor = ZRWhiteColor;
    
    _imagePickerController = [[UIImagePickerController alloc] init];
    _imagePickerController.delegate = self;
    _imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    _imagePickerController.allowsEditing = YES;
    
    
    [self setupNav];
    [self setupUI];
    [self loadData];
    [self setupAlertVC];
    [self setupPivkerView];
}

- (void)loadData{
    
    [[ZRNetworkTool sharedTool] getCategoryResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            self.dataArray = responseData[@"data"];
            
            [self.pickerView reloadAllComponents];
        }
    }];
    
    if (self.ID) {
        
        [[ZRNetworkTool sharedTool] getGoodsIfoResultWithGoodsID:self.ID WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                NSDictionary * dict = responseData[@"data"];
//                NSLog(@"dict===%@",dict);
                self.titleTextField.text = dict[@"merchants_goods_name"];
                self.priceTextField.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_discount_price"]];
                self.orignTextField.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_price"]];
//                self.telTextField.text = [NSString stringWithFormat:@"%@",dict[@"merchants_phone"]];
                [self.localButton setTitle:dict[@"merchants_goods_category_name"] forState:UIControlStateNormal];
                self.localButton.selected = YES;
                self.typeid = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_category"]];
//                self.infoTextView.text = dict[@"merchants_info"];
//                self.infoTextView.textColor =ZRBlackColor;
//                NSString *str = dict[@"merchants_goods_info"];
//                [self.webView loadHTMLString:str baseURL:nil];
                self.url = dict[@"merchants_goods_info"];
                self.repertoryTextfield.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_inventory"]];
                [self.normalDateEndButton setTitle:dict[@"merchants_goods_end_time"] forState:UIControlStateNormal];
                [self.normalDateStartButton setTitle:dict[@"merchants_goods_start_time"] forState:UIControlStateNormal];
                self.normalDateEndButton.selected = YES;
                self.normalDateStartButton.selected = YES;
                NSString * merchants_img = dict[@"merchants_goods_img"];
                NSArray * imgArray = [merchants_img componentsSeparatedByString:@","];
                [self.imgArray addObjectsFromArray:imgArray];
                self.count = self.imgArray.count;
                
                if (self.count > 2 && self.count < 5) {

                    self.addview.height = 200 * SCREENH6;
                    self.modeView.y = 440 * SCREENH6;
                }else if(self.count > 5 && self.count <= 9) {

                    self.addview.height = 300 * SCREENH6;
                    self.modeView.y = 540 * SCREENH6;
                }
                for (int i = 1; i < self.imgArray.count + 1; i++) {
                   
                    self.addview.count = i;
                    
                    NSString * str = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.imgArray[i - 1]];
                    NSURL * url = [NSURL URLWithString:str];
                    
                    self.addview.url = url;
                }
              
                
                int merchants_goods_type = [dict[@"merchants_goods_type"] intValue];
                if (merchants_goods_type == 1) {
                    //1普通
                    self.normalButton.selected = YES;
                    self.exploreImageView.hidden = YES;
                    self.tuanButton.selected = NO;
                    
                    self.modeView.height = 125 * SCREENH6;
                    self.tuanView.hidden = YES;
                    self.normalView.hidden = NO;
                    
                    NSString * merchants_goods_available_time = dict[@"merchants_goods_available_time"];
                    NSArray *array = [merchants_goods_available_time componentsSeparatedByString:@" "];
                    NSString * weekday = [NSString stringWithFormat:@"%@",array.firstObject];
                    for (WeekButton * btn in self.normalButtonArray) {
                        
                        if ([btn.titleLabel.text isEqualToString:weekday]) {
                            
                            btn.selected = YES;
                        }
                    }
                    NSString * time = array.lastObject;
                    NSArray * timeArr = [time componentsSeparatedByString:@"-"];
                    [self.normalTimeStartButton setTitle:timeArr.firstObject forState:UIControlStateNormal];
                    [self.normalTimeEndButton setTitle:timeArr.lastObject forState:UIControlStateNormal];
                    self.normalTimeStartButton.selected = YES;
                    self.normalTimeEndButton.selected = YES;
                    
//                    NSString * weekString = array.firstObject;
//                    NSArray * weekarray = [weekString componentsSeparatedByString:@"-"];
//                    for (WeekButton *button in subviews) {
//
//                        if (button.selected) {
//
//                            [muArr addObject:button.titleLabel.text];
//                        }
//                    }
                }else{
                    
                    self.maxPeopleButton.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_max_pople"]];
                    self.minPeopleButton.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_min_pople"]];
                    self.stopTimeTextfield.text = dict[@"merchants_goods_end_group_time"];
                    self.cancleTimeTextfield.text = [NSString stringWithFormat:@"%@",dict[@"merchants_goods_cancel_order_time"]];
        
                    self.tuanButton.selected = YES;
                    self.exploreImageView.hidden = NO;
                    self.normalButton.selected = NO;
                    self.modeView.height = 235 * SCREENH6;
                    self.tuanView.hidden = NO;
                    self.normalView.hidden = YES;
                    
                    NSArray * merchants_goods_available_time_weeks = dict[@"merchants_goods_available_time_weeks"];
                    
                    for (NSString * index in merchants_goods_available_time_weeks) {
                        
                        int indexPath = [index intValue];
                        
                        WeekButton * button = self.buttonArray[indexPath - 1];
                        
                        button.selected = YES;
                    }
                    
                    NSDictionary * merchants_goods_available_time = dict[@"merchants_goods_available_time"];
                    NSArray *keys = [merchants_goods_available_time allKeys];
                    NSArray * timeArray;
                    for (int i = 0; i < keys.count; i++)
                    {
                        timeArray = merchants_goods_available_time[keys[i]];
                    }

                    self.addCount = (int)timeArray.count;
                    
                    switch (self.addCount) {
                        case 1:
                            [self.oneStartButton setTitle:timeArray[0] forState:UIControlStateNormal];
                            self.oneStartButton.selected = YES;
                            break;
                        case 2:
                            self.twoStartButton.hidden = NO;
                            [self.oneStartButton setTitle:timeArray[0] forState:UIControlStateNormal];
                            self.oneStartButton.selected = YES;
                            [self.twoStartButton setTitle:timeArray[1] forState:UIControlStateNormal];
                            self.twoStartButton.selected = YES;
                            break;
                        case 3:
                            self.twoStartButton.hidden = NO;
                            self.threeStartButton.hidden = NO;
                            [self.oneStartButton setTitle:timeArray[0] forState:UIControlStateNormal];
                            self.oneStartButton.selected = YES;
                            [self.twoStartButton setTitle:timeArray[1] forState:UIControlStateNormal];
                            self.twoStartButton.selected = YES;
                            [self.threeStartButton setTitle:timeArray[2] forState:UIControlStateNormal];
                            self.threeStartButton.selected = YES;
                            break;
                        case 4:
                            self.twoStartButton.hidden = NO;
                            self.threeStartButton.hidden = NO;
                            self.fourStartButton.hidden = NO;
                            [self.oneStartButton setTitle:timeArray[0] forState:UIControlStateNormal];
                            self.oneStartButton.selected = YES;
                            [self.twoStartButton setTitle:timeArray[1] forState:UIControlStateNormal];
                            self.twoStartButton.selected = YES;
                            [self.threeStartButton setTitle:timeArray[2] forState:UIControlStateNormal];
                            self.threeStartButton.selected = YES;
                            [self.fourStartButton setTitle:timeArray[3] forState:UIControlStateNormal];
                            self.fourStartButton.selected = YES;
                            break;
                        case 5:
                            self.twoStartButton.hidden = NO;
                            self.threeStartButton.hidden = NO;
                            self.fourStartButton.hidden = NO;
                            self.fiveStartButton.hidden = NO;
                            [self.oneStartButton setTitle:timeArray[0] forState:UIControlStateNormal];
                            self.oneStartButton.selected = YES;
                            [self.twoStartButton setTitle:timeArray[1] forState:UIControlStateNormal];
                            self.twoStartButton.selected = YES;
                            [self.threeStartButton setTitle:timeArray[2] forState:UIControlStateNormal];
                            self.threeStartButton.selected = YES;
                            [self.fourStartButton setTitle:timeArray[3] forState:UIControlStateNormal];
                            self.fourStartButton.selected = YES;
                            [self.fiveStartButton setTitle:timeArray[4] forState:UIControlStateNormal];
                            self.fiveStartButton.selected = YES;
                            break;
                            
                        default:
                            break;
                    }
                    
                }
            }
            
            
        }];
    }else{
        
        [[ZRNetworkTool sharedTool] getMerchantsGoodsDefaultTimeWithBlock:^(BOOL success, id responseData) {

            if (success) {

                NSArray * array = responseData[@"data"];

                self.addCount = (int)array.count;

                if (array.count == 1) {

                    [self.oneStartButton setTitle:array.firstObject forState:UIControlStateNormal];
                    self.oneStartButton.selected = YES;
                    self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
                }else if (array.count == 2){

                    self.oneStartButton.selected = YES;
                    self.twoStartButton.selected = YES;
                    self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.twoStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    [self.oneStartButton setTitle:array.firstObject forState:UIControlStateNormal];
                    [self.twoStartButton setTitle:array[1] forState:UIControlStateNormal];
                }else if (array.count == 3){

                    self.oneStartButton.selected = YES;
                    self.twoStartButton.selected = YES;
                    self.threeStartButton.selected = YES;
                    self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.twoStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.threeStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    [self.oneStartButton setTitle:array.firstObject forState:UIControlStateNormal];
                    [self.twoStartButton setTitle:array[1] forState:UIControlStateNormal];
                    [self.threeStartButton setTitle:array[2] forState:UIControlStateNormal];
                }else if (array.count == 4){

                    self.oneStartButton.selected = YES;
                    self.twoStartButton.selected = YES;
                    self.threeStartButton.selected = YES;
                    self.fourStartButton.selected = YES;
                    self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.twoStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.threeStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.fourStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    [self.oneStartButton setTitle:array.firstObject forState:UIControlStateNormal];
                    [self.twoStartButton setTitle:array[1] forState:UIControlStateNormal];
                    [self.threeStartButton setTitle:array[2] forState:UIControlStateNormal];
                    [self.fourStartButton setTitle:array[3] forState:UIControlStateNormal];
                }else if (array.count == 5){

                    [self.oneStartButton setTitle:array.firstObject forState:UIControlStateNormal];
                    [self.twoStartButton setTitle:array[1] forState:UIControlStateNormal];
                    [self.threeStartButton setTitle:array[2] forState:UIControlStateNormal];
                    [self.fourStartButton setTitle:array[3] forState:UIControlStateNormal];
                    [self.fiveStartButton setTitle:array[4] forState:UIControlStateNormal];
                    self.oneStartButton.selected = YES;
                    self.twoStartButton.selected = YES;
                    self.threeStartButton.selected = YES;
                    self.fourStartButton.selected = YES;
                    self.fiveStartButton.selected = YES;
                    self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.twoStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.threeStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.fourStartButton.layer.borderColor = [ZRBlackColor CGColor];
                    self.fiveStartButton.layer.borderColor = [ZRBlackColor CGColor];
                }
            }
        }];
        
//        NSLog(@"buttonArray===%lu",(unsigned long)self.buttonArray.count);
        
        for (WeekButton * button in self.buttonArray) {
            
            button.selected = YES;
        }
    }
}

- (void)clickItemButton:(NSInteger )tag{
    
    self.count = tag;
    self.test = nil;
    [self presentViewController:self.alertVC animated:YES completion:nil];
}

- (void)clickDeleteButton:(NSInteger )tag{
    
    [self.imgArray removeObjectAtIndex:tag - 1];
    
    if (self.imgArray.count > 2 && self.imgArray.count <= 5) {
        
        self.addview.height = 200 * SCREENH6;
        self.modeView.y = 440 * SCREENH6;
    }else if(self.imgArray.count > 5 && self.imgArray.count <= 9) {
        
        self.addview.height = 300 * SCREENH6;
        self.modeView.y = 540 * SCREENH6;
    }else if(self.imgArray.count <= 2) {
        
        self.addview.height = 105 * SCREENH6;
        self.modeView.y = 340 * SCREENH6;
    }
}



- (void)setupNav{
    
    self.title = @"添加商品";
    
//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back(1)"] style:UIBarButtonItemStylePlain target:nil action:nil];
//    
//    self.navigationItem.backBarButtonItem = backItem;
    
    
    UIButton * rightButton = [[UIButton alloc] init];
    
    rightButton.tag = 2;
    [rightButton setTitle:@"发布" forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(didNavButton:) forControlEvents:UIControlEventTouchUpInside];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [rightButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    
    UIBarButtonItem * rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    self.navigationItem.rightBarButtonItem = rightBar;
}


- (void)setupUI{
    
    UIScrollView * scrollView = [[UIScrollView alloc]init];
    
    self.scrollView = scrollView;
    
    [self.view addSubview:self.scrollView];
   
    UIView * container = [UIView new];
    
    self.container = container;
    
    [scrollView addSubview:self.container];
    
    self.addview = [[AddPictureView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 105 * SCREENH6)];
    self.addview.addPictureViewDelegate = self;
    
    [self.scrollView addSubview:self.addview];
    
    self.titleImageView = [self setupImageViewWithImage:@"标题"];
    [self.scrollView addSubview:self.titleImageView];
    self.moneyImageView = [self setupImageViewWithImage:@"价格"];
    [self.scrollView addSubview:self.moneyImageView];
    self.orignImageView = [self setupImageViewWithImage:@"批量设定原价"];
    [self.scrollView addSubview:self.orignImageView];
//    self.telImageView = [self setupImageViewWithImage:@"电话"];
//    [self.scrollView addSubview:self.telImageView];
    self.localImageView = [self setupImageViewWithImage:@"商品分类"];
    [self.scrollView addSubview:self.localImageView];
    self.openTimeImageView = [self setupImageViewWithImage:@"营业时间"];
    [self.scrollView addSubview:self.openTimeImageView];
    self.vailImageView = [self setupImageViewWithImage:@"标题"];
    [self.scrollView addSubview:self.vailImageView];
    self.sellImageView = [self setupImageViewWithImage:@"销售"];
    [self.scrollView addSubview:self.sellImageView];
    self.exploreImageView = [self setupImageViewWithImage:@"说明"];
    self.exploreImageView.hidden = YES;
    [self.scrollView addSubview:self.exploreImageView];
    self.timeImageView = [self setupImageViewWithImage:@"时间"];
    [self.scrollView addSubview:self.timeImageView];
    
    self.titleNameLabel = [self setupLabelWithTitle:@"标题/名字:"];
    [self.scrollView addSubview:self.titleNameLabel];
    self.priceLabel = [self setupLabelWithTitle:@"价格:"];
    [self.scrollView addSubview:self.priceLabel];
    self.orignLabel = [self setupLabelWithTitle:@"原价:"];
    [self.scrollView addSubview:self.orignLabel];
//    self.telLabel = [self setupLabelWithTitle:@"联系方式:"];
//    [self.scrollView addSubview:self.telLabel];
    self.localLabel = [self setupLabelWithTitle:@"商品分类:"];
    [self.scrollView addSubview:self.localLabel];
    self.openLabel = [self setupLabelWithTitle:@"营业时间:"];
    [self.scrollView addSubview:self.openLabel];
    self.vailLabel = [self setupLabelWithTitle:@"有效日期:"];
    [self.scrollView addSubview:self.vailLabel];
    self.sellLabel = [self setupLabelWithTitle:@"销售模式:"];
    [self.scrollView addSubview:self.sellLabel];
    
    self.titleTextField = [self setupTextFiledWithPlaceHolderString:@"给你的商品取个名字吧!"];
    [self.scrollView addSubview:self.titleTextField];
    self.priceTextField = [self setupTextFiledWithPlaceHolderString:@"￥00.00"];
    self.priceTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [self.scrollView addSubview:self.priceTextField];
    self.orignTextField = [self setupTextFiledWithPlaceHolderString:@"￥00.00"];
    self.orignTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [self.scrollView addSubview:self.orignTextField];
//    self.telTextField = [self setupTextFiledWithPlaceHolderString:@"请输入您的联系方式"];
//    [self.scrollView addSubview:self.telTextField];
    
    self.threeLineView = [self setupLineView];
    [self.scrollView addSubview:self.threeLineView];
    self.fourLineView = [self setupLineView];
    [self.scrollView addSubview:self.fourLineView];
//    self.fiveLineView = [self setupLineView];
//    [self.scrollView addSubview:self.fiveLineView];

    UIButton * localButton = [UIButton new];
    
    localButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    localButton.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    [localButton setBackgroundColor:ColorWithRGB(0xEFF0F1)];
    [localButton setTitle:@" 请选择商品类型" forState:UIControlStateNormal];
    [localButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [localButton setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [localButton addTarget:self action:@selector(clickLocalButton) forControlEvents:UIControlEventTouchUpInside];
    localButton.layer.cornerRadius = 5;
    localButton.layer.masksToBounds = YES;
    
    self.localButton = localButton;
    [self.scrollView addSubview:self.localButton];
    
    self.normalButton = [self setupButtonWithTitle:@"  普通模式"];
    self.normalButton.selected = YES;
    [self.scrollView addSubview:self.normalButton];
    self.tuanButton = [self setupButtonWithTitle:@"  拼团模式"];
    [self.scrollView addSubview:self.tuanButton];
    
    UIView * modelView = [[UIView alloc] initWithFrame:CGRectMake(15 * SCREENH6, 320 * SCREENH6 + 20 * SCREENH6, 345 * SCREENH6, 125 * SCREENH6)];
    
    modelView.backgroundColor = ColorWithRGB(0xEDEEEF);
    modelView.userInteractionEnabled = YES;
    
    self.modeView = modelView;
    
    [self.scrollView addSubview:self.modeView];
    
#define Start_X          55 * SCREENH6      // 第一个按钮的X坐标
#define Start_Y          10 * SCREENH6     // 第一个按钮的Y坐标
#define Width_Space      10 * SCREENH6      // 2个按钮之间的横间距
#define Button_Height   30 * SCREENH6    // 高
#define Button_Width    25 * SCREENH6    // 宽
    
    
    UIView * normalView = [UIView new];
    
    normalView.backgroundColor = ColorWithRGB(0xEDEEEF);
    normalView.userInteractionEnabled = YES;
    
    self.normalView = normalView;
    
    [self.modeView addSubview:self.normalView];
    
    UIView * normalWeekView = [UIView new];

    normalWeekView.backgroundColor = ColorWithRGB(0xEDEEEF);
    normalWeekView.userInteractionEnabled = YES;

    self.normalWeekView = normalWeekView;

    [self.normalView addSubview:self.normalWeekView];
    
    self.validTimeLabel = [self setupSmallLabelWithTitle:@"可用\n时间"];
    self.validTimeLabel.numberOfLines = 2;
    [self.normalView addSubview:self.validTimeLabel];
    self.repertoryLabel = [self setupSmallLabelWithTitle:@"商品\n库存"];
    self.repertoryLabel.numberOfLines = 2;
    [self.normalView addSubview:self.repertoryLabel];
    self.validDateLabel = [self setupLabelWithTitle:@"截止日期"];
    [self.scrollView addSubview:self.validDateLabel];
    self.normalTimeStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    [self.normalView addSubview:self.normalTimeStartButton];
    self.normalTimeEndButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    [self.normalView addSubview:self.normalTimeEndButton];
    self.threeLineView = [self setupLineView];
    [self.normalView addSubview:self.threeLineView];
    self.fiveLineView = [self setupLineView];
    [self.normalView addSubview:self.fiveLineView];
    self.normalDateStartButton = [self setupLayarButtonWithTitle:@" 请选择 "];
    self.normalDateStartButton.titleLabel.font = [UIFont systemFontOfSize:9 * SCREENH6];
    [self.scrollView addSubview:self.normalDateStartButton];
    self.normalDateEndButton = [self setupLayarButtonWithTitle:@" 请选择 "];
    self.normalDateEndButton.titleLabel.font = [UIFont systemFontOfSize:9 * SCREENH6];
    [self.scrollView addSubview:self.normalDateEndButton];
    self.oneToLabel = [self setupToLabelWithTitle:@"至"];
    [self.normalView addSubview:self.oneToLabel];
    self.twoToLabel = [self setupToLabelWithTitle:@"至"];
    [self.scrollView addSubview:self.twoToLabel];
    self.repertoryTextfield = [self setupTextField];
    self.repertoryTextfield.keyboardType = UIKeyboardTypeDecimalPad;
    [self.normalView addSubview:self.repertoryTextfield];
    
//    for (int i = 0; i < 7; i++) {
//
//        // 圆角按钮
//        WeekButton * weekButton = [WeekButton new];
//        weekButton.tag = i;//这句话不写等于废了
//        weekButton.frame = CGRectMake(i * (Button_Width + Width_Space) + Start_X, Start_Y, Button_Width, Button_Height);
//        switch (i) {
//            case 0:
//                [weekButton setTitle:@"周一" forState:UIControlStateNormal];
//                break;
//            case 1:
//                [weekButton setTitle:@"周二" forState:UIControlStateNormal];
//                break;
//            case 2:
//                [weekButton setTitle:@"周三" forState:UIControlStateNormal];
//                break;
//            case 3:
//                [weekButton setTitle:@"周四" forState:UIControlStateNormal];
//                break;
//            case 4:
//                [weekButton setTitle:@"周五" forState:UIControlStateNormal];
//                break;
//            case 5:
//                [weekButton setTitle:@"周六" forState:UIControlStateNormal];
//                break;
//            case 6:
//                [weekButton setTitle:@"周日" forState:UIControlStateNormal];
//                break;
//
//            default:
//                break;
//        }
//
//        [weekButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        [weekButton setTitleColor:ZRBlackColor forState:UIControlStateSelected];
//        [weekButton setImage:[UIImage imageNamed:@"圆角矩形6拷贝"] forState:UIControlStateNormal];
//        [weekButton setImage:[UIImage imageNamed:@"绿色勾选"] forState:UIControlStateSelected];
//        weekButton.titleLabel.font = [UIFont systemFontOfSize:10 * SCREENH6];
//        [self.normalWeekView addSubview:weekButton];
//        //按钮点击方法
//        [weekButton addTarget:self action:@selector(weekBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//
//        [self.normalButtonArray addObject:weekButton];
//    }
    self.workButton = [self setupWeekButtonWith:@"工作日"];
    [self.normalView addSubview:self.workButton];
    self.weekendsButton = [self setupWeekButtonWith:@"周末"];
    [self.normalView addSubview:self.weekendsButton];
    self.everydayButton = [self setupWeekButtonWith:@"每天"];
    [self.normalView addSubview:self.everydayButton];
    
    UIView * tuanView = [UIView new];
    
    tuanView.backgroundColor = ColorWithRGB(0xEDEEEF);
    tuanView.userInteractionEnabled = YES;
    tuanView.hidden = YES;
    
    self.tuanView = tuanView;
    
    [self.modeView addSubview:self.tuanView];
    
    UIView * tuanWeekView = [UIView new];
    
    tuanWeekView.backgroundColor = ColorWithRGB(0xEDEEEF);
    tuanWeekView.userInteractionEnabled = YES;
    
    self.tuanWeekView = tuanWeekView;
    
    [self.tuanView addSubview:self.tuanWeekView];

    
    self.tuanDateLabel = [self setupSmallLabelWithTitle:@"日期"];
    [self.tuanView addSubview:self.tuanDateLabel];
    self.oneLineView = [self setupLineView];
    [self.tuanView addSubview:self.oneLineView];
    self.tuanTimeLabel = [self setupSmallLabelWithTitle:@"开团\n时间"];
    self.tuanTimeLabel.numberOfLines = 2;
    [self.tuanView addSubview:self.tuanTimeLabel];
    self.cancleLabel = [self setupSmallLabelWithTitle:@"取消\n拼团"];
    self.cancleLabel.numberOfLines = 2;
    [self.tuanView addSubview:self.cancleLabel];
    self.stopTimeLabel = [self setupSmallLabelWithTitle:@"截止\n时限"];
    self.stopTimeLabel.numberOfLines = 2;
    [self.tuanView addSubview:self.stopTimeLabel];
    self.fourLineView = [self setupLineView];
    [self.tuanView addSubview:self.fourLineView];
    self.sixLineView = [self setupLineView];
    [self.tuanView addSubview:self.sixLineView];
    self.numPeopleLabel = [self setupSmallLabelWithTitle:@"人数"];
    [self.tuanView addSubview:self.numPeopleLabel];
    self.twoLineView = [self setupLineView];
    [self.tuanView addSubview:self.twoLineView];
    self.minPeopleButton = [self setupTextField];
    self.minPeopleButton.keyboardType = UIKeyboardTypeDecimalPad;
    [self.tuanView addSubview:self.minPeopleButton];
    self.maxPeopleButton = [self setupTextField];
    self.maxPeopleButton.keyboardType = UIKeyboardTypeDecimalPad;
    [self.tuanView addSubview:self.maxPeopleButton];
    self.threeToLabel = [self setupToLabelWithTitle:@"至"];
    [self.tuanView addSubview:self.threeToLabel];
    self.oneStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    [self.tuanView addSubview:self.oneStartButton];
    self.twoStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    self.twoStartButton.hidden = YES;
    [self.tuanView addSubview:self.twoStartButton];
    self.threeStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    self.threeStartButton.hidden = YES;
    [self.tuanView addSubview:self.threeStartButton];
    self.fourStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    self.fourStartButton.hidden = YES;
    [self.tuanView addSubview:self.fourStartButton];
    self.fiveStartButton = [self setupLayarButtonWithTitle:@" 00:00 "];
    self.fiveStartButton.hidden = YES;
    [self.tuanView addSubview:self.fiveStartButton];
    self.earlyLabel = [self setupToLabelWithTitle:@"提前"];
    [self.tuanView addSubview:self.earlyLabel];
    self.hourLabel = [self setupToLabelWithTitle:@"小时,截止拼团"];
    [self.tuanView addSubview:self.hourLabel];
    self.cancleEarlyLabel = [self setupToLabelWithTitle:@"提前"];
    [self.tuanView addSubview:self.cancleEarlyLabel];
    self.earlyHourLabel = [self setupToLabelWithTitle:@"小时,可取消订单"];
    [self.tuanView addSubview:self.earlyHourLabel];
    
    self.stopTimeTextfield = [self setupTextField];
    self.stopTimeTextfield.text = @"1";
    self.stopTimeTextfield.keyboardType = UIKeyboardTypeDecimalPad;
    [self.tuanView addSubview:self.stopTimeTextfield];
    self.cancleTimeTextfield = [self setupTextField];
    self.cancleTimeTextfield.text = @"6";
    self.cancleTimeTextfield.keyboardType = UIKeyboardTypeDecimalPad;
    [self.tuanView addSubview:self.cancleTimeTextfield];
    
    UIButton * addButton = [[UIButton alloc] initWithFrame:CGRectMake(138 * SCREENH6, 62 * SCREENH6, 20 * SCREENH6, 20 * SCREENH6)];
    
    [addButton setImage:[UIImage imageNamed:@"加"] forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(clickAddButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.addButton = addButton;
    
    [self.tuanView addSubview:self.addButton];
    
    UIButton * subtractButton = [[UIButton alloc] initWithFrame:CGRectMake(108 * SCREENH6, 62 * SCREENH6, 20 * SCREENH6, 20 * SCREENH6)];
    
    [subtractButton setImage:[UIImage imageNamed:@"减"] forState:UIControlStateNormal];
    [subtractButton addTarget:self action:@selector(clickAddButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.subtractButton = subtractButton;
    
    [self.tuanView addSubview:self.subtractButton];
    
    for (int i = 0; i < 7; i++) {
        
        // 圆角按钮
        WeekButton * weekButton = [WeekButton new];
        weekButton.tag = i;//这句话不写等于废了
        weekButton.frame = CGRectMake(i * (Button_Width + Width_Space) + Start_X, Start_Y, Button_Width, Button_Height);
        switch (i) {
            case 0:
                [weekButton setTitle:@"周一" forState:UIControlStateNormal];
                weekButton.tag = 1;
                break;
            case 1:
                [weekButton setTitle:@"周二" forState:UIControlStateNormal];
                weekButton.tag = 2;
                break;
            case 2:
                [weekButton setTitle:@"周三" forState:UIControlStateNormal];
                weekButton.tag = 3;
                break;
            case 3:
                [weekButton setTitle:@"周四" forState:UIControlStateNormal];
                weekButton.tag = 4;
                break;
            case 4:
                [weekButton setTitle:@"周五" forState:UIControlStateNormal];
                weekButton.tag = 5;
                break;
            case 5:
                [weekButton setTitle:@"周六" forState:UIControlStateNormal];
                weekButton.tag = 6;
                break;
            case 6:
                [weekButton setTitle:@"周日" forState:UIControlStateNormal];
                weekButton.tag = 7;
                break;
                
            default:
                break;
        }
        
        [weekButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [weekButton setTitleColor:ZRBlackColor forState:UIControlStateSelected];
        [weekButton setImage:[UIImage imageNamed:@"圆角矩形6拷贝"] forState:UIControlStateNormal];
        [weekButton setImage:[UIImage imageNamed:@"绿色勾选"] forState:UIControlStateSelected];
        weekButton.titleLabel.font = [UIFont systemFontOfSize:10 * SCREENH6];
        [self.tuanWeekView addSubview:weekButton];
        //按钮点击方法
        [weekButton addTarget:self action:@selector(weekBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.buttonArray addObject:weekButton];
    }
    
    
    // 创建textView
//    UITextView * infoTextView =[[UITextView alloc] init];
//
//    infoTextView.backgroundColor= ColorWithRGB(0xEFF0F1);
//    infoTextView.text = @"详细介绍";
//    infoTextView.font = [UIFont systemFontOfSize:14 * SCREENH6];
//    infoTextView.textColor = ColorWithRGB(0xbebebe);
//    infoTextView.delegate = self;
//
//    self.infoTextView = infoTextView;
//    [self.scrollView addSubview:self.infoTextView];
    
    
    self.webView = [UIWebView new];
    
    self.webView.delegate = self;
    self.webView.backgroundColor = ColorWithRGB(0xEFF0F1);
    
    NSBundle *bundle = [NSBundle mainBundle];
    NSURL *indexFileURL = [bundle URLForResource:@"richTextEditor" withExtension:@"html"];
    
    [self.webView setKeyboardDisplayRequiresUserAction:NO];
    [self.webView loadRequest:[NSURLRequest requestWithURL:indexFileURL]];
    
    [self.scrollView addSubview:self.webView];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor colorWithRed:0.78 green:0.78 blue:0.78 alpha:1];
//    btn.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 100, [UIScreen mainScreen].bounds.size.height - 40, 80, 30);
    btn.layer.cornerRadius = 5;
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn setTitle:@"添加图片" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.addPictureButton = btn;
    
    [self.webView addSubview:self.addPictureButton];
    
    [btn addTarget:self action:@selector(addImage) forControlEvents:UIControlEventTouchUpInside];  
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    if (self.url.length > 0)
    {
        NSString *place = [NSString stringWithFormat:@"window.placeHTMLToEditor('%@')",self.url];
        [webView stringByEvaluatingJavaScriptFromString:place];
    }
}


- (void)addImage
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.delegate = self;
    self.test = @"test";
    [self presentViewController:imagePickerController animated:YES completion:nil];
}



- (void)viewDidLayoutSubviews{
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
    
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.scrollView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.addview.mas_bottom).offset(10 * SCREENH6);
        make.height.width.mas_equalTo(15 * SCREENH6);
    }];
    
    [self.titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleImageView);
        make.leading.mas_equalTo(self.titleImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.titleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleNameLabel);
        make.top.mas_equalTo(self.titleNameLabel.mas_bottom).offset(5 * SCREENH6);
        make.height.mas_equalTo(25 * SCREENH6);
        make.trailing.mas_equalTo(self.scrollView).offset(-15 * SCREENH6);
    }];

    [self.moneyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleImageView);
        make.top.mas_equalTo(self.titleTextField.mas_bottom).offset(20 * SCREENH6);
        make.width.mas_equalTo(12 * SCREENH6);
        make.height.mas_equalTo(15 * SCREENH6);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.moneyImageView);
        make.leading.mas_equalTo(self.moneyImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.orignImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.scrollView.mas_centerX).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.moneyImageView);
        make.width.height.mas_equalTo(15 * SCREENH6);
    }];
    
    [self.orignLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.orignImageView);
        make.leading.mas_equalTo(self.orignImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.priceTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.titleTextField);
        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(5 * SCREENH6);
        make.width.mas_equalTo(140 * SCREENH6);
    }];
    
    [self.orignTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.height.mas_equalTo(self.titleTextField);
        make.top.mas_equalTo(self.orignLabel.mas_bottom).offset(5 * SCREENH6);
        make.leading.mas_equalTo(self.orignLabel);
    }];

//    [self.telImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.moneyImageView);
//        make.width.height.mas_equalTo(12 * SCREENH6);
//        make.top.mas_equalTo(self.priceTextField.mas_bottom).offset(20 * SCREENH6);
//    }];
//
//    [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.priceLabel);
//        make.centerY.mas_equalTo(self.telImageView);
//    }];
//
//    [self.telTextField mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.height.trailing.mas_equalTo(self.titleTextField);
//        make.top.mas_equalTo(self.telLabel.mas_bottom).offset(5 * SCREENH6);
//    }];
    
    [self.localImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.moneyImageView);
        make.top.mas_equalTo(self.priceTextField.mas_bottom).offset(20 * SCREENH6);
        make.width.mas_equalTo(13 * SCREENH6);
        make.height.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.localLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.priceLabel);
        make.centerY.mas_equalTo(self.localImageView);
    }];
    
    [self.localButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.titleTextField);
        make.top.mas_equalTo(self.localLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.sellImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.localImageView);
        make.top.mas_equalTo(self.localButton.mas_bottom).offset(20 * SCREENH6);
        make.width.height.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.sellLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.localLabel);
        make.centerY.mas_equalTo(self.sellImageView);
    }];
    
    [self.normalButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sellLabel.mas_trailing).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.sellLabel);
    }];

    [self.tuanButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.normalButton.mas_trailing).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.normalButton);
    }];

    [self.exploreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.tuanButton);
        make.leading.mas_equalTo(self.tuanButton.mas_trailing).offset(1 * SCREENH6);
    }];
    
//    [self.modeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.sellImageView);
//        make.trailing.mas_equalTo(self.localButton);
//        make.top.mas_equalTo(self.sellImageView.mas_bottom).offset(20 * SCREENH6);
//        make.height.mas_equalTo(150 * SCREENH6);
//    }];
    
    [self.normalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.modeView);
    }];
    
    [self.normalWeekView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.mas_equalTo(self.normalView);
        make.height.mas_equalTo(50 * SCREENH6);
    }];
    
    [self.validTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sellLabel);
        make.top.mas_equalTo(self.normalView).offset(10 * SCREENH6);
    }];
    
    [self.workButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.normalView).offset(65 * SCREENH6);
        make.centerY.mas_equalTo(self.validTimeLabel);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.weekendsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workButton.mas_trailing).offset(10 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.workButton);
    }];

    [self.everydayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.weekendsButton.mas_trailing).offset(10 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.weekendsButton);
    }];
  
    [self.normalTimeStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.normalView).offset(65 * SCREENH6);
        make.top.mas_equalTo(self.validTimeLabel.mas_bottom).offset(10 * SCREENH6);
        make.width.mas_equalTo(45 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.oneToLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.normalTimeStartButton);
        make.leading.mas_equalTo(self.normalTimeStartButton.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.normalTimeEndButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.normalTimeStartButton);
        make.leading.mas_equalTo(self.oneToLabel.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.threeLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        make.leading.mas_equalTo(self.validTimeLabel);
        make.trailing.mas_equalTo(self.normalView).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.normalTimeEndButton.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.repertoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.threeLineView);
        make.top.mas_equalTo(self.threeLineView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.repertoryTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.normalTimeStartButton);
        make.centerY.mas_equalTo(self.repertoryLabel);
        make.width.mas_equalTo(100 * SCREENH6);
        make.height.mas_equalTo(25 * SCREENH6);
    }];
    
//    [self.fiveLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.trailing.height.mas_equalTo(self.threeLineView);
//        make.top.mas_equalTo(self.repertoryTextfield.mas_bottom).offset(12 * SCREENH6);
//    }];
    
    [self.tuanView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.modeView);
    }];
    
    [self.tuanWeekView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.mas_equalTo(self.tuanView);
        make.height.mas_equalTo(50 * SCREENH6);
    }];
    
    [self.tuanDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sellLabel);
        make.top.mas_equalTo(self.tuanView).offset(10 * SCREENH6);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        make.leading.mas_equalTo(self.tuanDateLabel);
        make.trailing.mas_equalTo(self.tuanView).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.tuanView).offset(45 * SCREENH6);
    }];
    
    [self.tuanTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.tuanDateLabel);
        make.top.mas_equalTo(self.oneLineView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.oneStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.tuanTimeLabel);
        make.leading.mas_equalTo(self.tuanView).offset(55 * SCREENH6);
        make.height.mas_equalTo(25 * SCREENH6);
        make.width.mas_equalTo(45 * SCREENH6);
    }];
    
    [self.twoStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.oneStartButton);
        make.leading.mas_equalTo(self.oneStartButton.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.threeStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.twoStartButton);
        make.leading.mas_equalTo(self.twoStartButton.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.fourStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.threeStartButton);
        make.leading.mas_equalTo(self.threeStartButton.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.fiveStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.fourStartButton);
        make.leading.mas_equalTo(self.fourStartButton.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.oneLineView);
        make.top.mas_equalTo(self.tuanTimeLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.cancleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.tuanTimeLabel);
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.cancleEarlyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.tuanView).offset(55 * SCREENH6);
        make.centerY.mas_equalTo(self.cancleLabel);
    }];
    
    [self.cancleTimeTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.cancleEarlyLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.cancleEarlyLabel);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.earlyHourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.cancleTimeTextfield.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.cancleTimeTextfield);
    }];
    
    [self.sixLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.twoLineView);
        make.top.mas_equalTo(self.cancleLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.stopTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.cancleLabel);
        make.top.mas_equalTo(self.sixLineView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.earlyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.tuanView).offset(55 * SCREENH6);
        make.centerY.mas_equalTo(self.stopTimeLabel);
    }];
    
    [self.stopTimeTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.earlyLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.earlyLabel);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.hourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopTimeTextfield.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.stopTimeTextfield);
    }];
    
    [self.fourLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.twoLineView);
        make.top.mas_equalTo(self.stopTimeLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.numPeopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopTimeLabel);
        make.top.mas_equalTo(self.fourLineView.mas_bottom).offset(13 * SCREENH6);
    }];
    
    [self.minPeopleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.tuanView).offset(55 * SCREENH6);
        make.centerY.mas_equalTo(self.numPeopleLabel);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.threeToLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.minPeopleButton);
        make.leading.mas_equalTo(self.minPeopleButton.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.maxPeopleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.minPeopleButton);
        make.leading.mas_equalTo(self.threeToLabel.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.timeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sellImageView);
        make.top.mas_equalTo(self.modeView.mas_bottom).offset(20 * SCREENH6);
        make.width.height.mas_equalTo(15 * SCREENH6);
    }];
    
    [self.validDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sellLabel);
        make.centerY.mas_equalTo(self.timeImageView);
    }];
    
    [self.normalDateStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.validDateLabel.mas_trailing).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.validDateLabel);
        make.width.mas_equalTo(110 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];

    [self.twoToLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.normalDateStartButton);
        make.leading.mas_equalTo(self.normalDateStartButton.mas_trailing).offset(10 * SCREENH6);
    }];

    [self.normalDateEndButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.twoToLabel.mas_trailing).offset(10 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.normalDateStartButton);
//        make.width.mas_equalTo(80 * SCREENH6);
//        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.modeView);
        make.top.mas_equalTo(self.validDateLabel.mas_bottom).offset(15 * SCREENH6);
        make.height.mas_equalTo(350 * SCREENH6);
        make.bottom.mas_equalTo(self.container).offset(-20 * SCREENH6);
    }];
    
    [self.addPictureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.view).offset(-5 * SCREENH6);
        make.bottom.mas_equalTo(self.webView).offset(-5 * SCREENH6);
        make.width.mas_equalTo(80 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
}


- (void)setupPivkerView{
    
    self.bgView = [[UIView alloc]init];
    self.bgView.frame = CGRectMake(0, kScreenH, kScreenW, kScreenH / 3);
    self.bgView.backgroundColor = ZRWhiteColor;
    [self.view addSubview:self.bgView];
    
    UIView *btnView = [[UIView alloc]init];
    btnView.frame = CGRectMake(0, 0, kScreenW, 40 * SCREENH6);
    btnView.backgroundColor = ColorWithRGB(0xababab);
    [self.bgView addSubview:btnView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(10 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [sureBtn setTitle:@"取消" forState:UIControlStateNormal];
    [sureBtn setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:sureBtn];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(self.view.frame.size.width - 70 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [cancelBtn setTitle:@"确定" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(sureBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:cancelBtn];
    
    float height = kScreenH / 3 - 40 * SCREENH6;
    self.pickerView = [[UIPickerView alloc]init];
    self.pickerView.frame = CGRectMake(0, 40 * SCREENH6, kScreenW, height);
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    [self.bgView addSubview:self.pickerView];
}


// 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// 每列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return self.dataArray.count;
}


// 返回每一行的内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    
    NSDictionary * dict = self.dataArray[row];
    
    NSString * bankInfo = [NSString stringWithFormat:@"%@",dict[@"name"]];
    
    return bankInfo;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
    _typeIndex = row;
}


- (void)cancelBtn{
    
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgView.frame = CGRectMake(0, self.view.frame.size.height, kScreenW, kScreenH / 3);
    } completion:^(BOOL finished) {
    }];
    
}


- (void)sureBtn{
    
    NSDictionary * dict = self.dataArray[_typeIndex];
    
    NSString * type = [NSString stringWithFormat:@" %@",dict[@"name"]];
    self.typeid = dict[@"id"];
    
    [self.localButton setTitle:type forState:UIControlStateNormal];
    self.localButton.selected = YES;
//    [self reloadButtonState];
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, kScreenH / 3);
    } completion:^(BOOL finished) {
    }];
}


- (UITextField *)setupTextField{
    
    UITextField * textField = [UITextField new];
    
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.backgroundColor = ColorWithRGB(0xEDEEEF);
    textField.layer.borderColor = [ZRBlackColor CGColor];
    textField.layer.borderWidth = 1.0f;
    textField.layer.cornerRadius = 5 * SCREENH6;
    textField.layer.masksToBounds = YES;
    
    //设置光标颜色
    textField.tintColor = ZRBlackColor;
    textField.font = [UIFont systemFontOfSize:14 * SCREENH6];
    textField.textColor = ZRBlackColor;
    
    return textField;
}


- (UILabel *)setupToLabelWithTitle:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.text = title;
    label.textColor = [UIColor lightGrayColor];
    label.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    return label;
}


- (UIButton *)setupLayarButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickChooseTimeButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    button.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    button.layer.cornerRadius = 5;
    button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    button.layer.borderWidth = 1 * SCREENH6;
    button.layer.masksToBounds = YES;
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    return button;
}


- (UIButton *)setupButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"椭圆2"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"选中椭圆"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(clickChooseModelButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    return button;    
}

- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xCBCCCD);
    
    return lineView;
}


- (UITextField *)setupTextFiledWithPlaceHolderString:(NSString *)string{
    
    UITextField * textField = [[UITextField alloc] init];
    
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.backgroundColor = ColorWithRGB(0xEDEEEF);
    
    //设置光标颜色
    textField.tintColor = ZRBlackColor;
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:string attributes:attrs];
    textField.font = [UIFont systemFontOfSize:14 * SCREENH6];
    textField.textColor = ZRBlackColor;
//    textField.keyboardAppearance = UIKeyboardAppearanceDark;
    
    return textField;
}


- (UIImageView *)setupImageViewWithImage:(NSString *)image{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.image = [UIImage imageNamed:image];
    
    return imageView;
}

- (UILabel *)setupLabelWithTitle:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.text = title;
    label.textColor = ZRBlackColor;
    label.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    return label;
}


- (UILabel *)setupSmallLabelWithTitle:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.text = title;
    label.textColor = ZRBlackColor;
    label.font = [UIFont systemFontOfSize:12 * SCREENH6];
    
    return label;
}


#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"详细介绍";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"详细介绍"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}


- (void)setupAlertVC{
    
    self.alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"选择照片方式" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * camerAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * albumsAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [self.alertVC addAction:camerAction];
    [self.alertVC addAction:albumsAction];
    [self.alertVC addAction:cancelAction];
    
}

#pragma mark -实现图片选择器代理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; //通过key值获取到图片
    //给UIimageView赋值已经选择的相片
    NSData *frontImageData = UIImageJPEGRepresentation(image,0.5);
    NSString *base64Data = [frontImageData base64EncodedStringWithOptions:0];
    NSString * reslut = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",base64Data];
    
    if (self.test) {
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSDate *now = [NSDate date];
        NSString *imageName = [NSString stringWithFormat:@"iOS%@.jpg", [self stringFromDate:now]];
        NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:imageName];
//        NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
        UIImage *imageWeb;
        //        if ([mediaType isEqualToString:@"public.image"])
        //        {
        imageWeb = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *imageData = UIImageJPEGRepresentation(imageWeb, 0.5);
        [imageData writeToFile:imagePath atomically:YES];
        NSString * webData = [imageData base64EncodedStringWithOptions:0];
        NSString * webReslut = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",webData];
//        }
        //此处是将图片上传ftp中特定位置并使用时间戳命名 该图片地址替换到html文件中去
        //上传图片到服务器--在这里进行图片上传的网络请求，这里不再介绍
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:webReslut WithBlock:^(BOOL success, id responseData) {
            
//            NSLog(@"res===%@",responseData);
            if (success) {
                
                NSString * string = [NSString stringWithFormat:@"%@",responseData[@"data"]];
                
                NSString * url = [NSString stringWithFormat:@"%@%@",BASEURLSTR,string];
                
                NSString *script = [NSString stringWithFormat:@"window.insertImage('%@', '%@')", url, imagePath];
                
                [self.webView stringByEvaluatingJavaScriptFromString:script];
            }
        }];
        
    }else{
        
        //上传图片到服务器--在这里进行图片上传的网络请求，这里不再介绍
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                if (self.count > 2 && self.count < 5) {
                    
                    self.addview.height = 200 * SCREENH6;
                    self.modeView.y = 440 * SCREENH6;
                }else if(self.count > 5 && self.count <= 9) {
                    
                    self.addview.height = 300 * SCREENH6;
                    //        NSLog(@"self.count < 9=== %f",self.modeView.y);
                    //        self.modeView.y = self.modeView.y + 100 * SCREENH6;
                    self.modeView.y = 540 * SCREENH6;
                }
                
                self.addview.count = self.count;
                self.addview.buttonImage = image;
                
                NSString * string = [NSString stringWithFormat:@"%@",responseData[@"data"]];
                
                [self.imgArray addObject:string];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }
    
}

//当用户取消选择的时候，调用该方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}


- (void)clickLocalButton{

    [self.titleTextField resignFirstResponder];
    [self.priceTextField resignFirstResponder];
    [self.orignTextField resignFirstResponder];
    [UIView animateWithDuration:0.5 animations:^{
        self.bgView.frame = CGRectMake(0, kScreenH - kScreenH / 3, kScreenW, kScreenH / 3);
    }];
}


- (void)clickAddButton:(UIButton *)button{
    
//    if (self.addCount == 1) {
//
//        self.addCount = self.addCount + 1;
////        self.twoStartButton.hidden = NO;
////        self.addButton.x = self.addButton.x + 53 * SCREENH6;
//
//    }else if (self.addCount == 2){
//
//        self.addCount = self.addCount + 1;
////self.threeStartButton.hidden = NO;
////        self.addButton.x = self.addButton.x +53 * SCREENH6;
//    }else if (self.addCount == 3){
//
//        self.addCount = self.addCount + 1;
////        self.fourStartButton.hidden = NO;
////        self.addButton.x = self.addButton.x +53 * SCREENH6;
//    }else if (self.addCount == 4){
//
//        self.addCount = self.addCount + 1;
////        self.fiveStartButton.hidden = NO;
////        self.addButton.hidden = YES;
//    }
    
    if (button == self.addButton) {
        
        self.addCount = self.addCount + 1;
    }else{
        
        if (self.addCount > 1) {
            
            self.addCount = self.addCount - 1;
        }else{
            
            self.addCount =  1;
        }
        
    }
}

- (void)setAddCount:(int)addCount{
    
    _addCount = addCount;
    
    if (addCount == 1) {
        
//        self.twoStartButton.hidden = NO;
        self.addButton.hidden = NO;
        self.twoStartButton.hidden = YES;
        self.threeStartButton.hidden = YES;
        self.fourStartButton.hidden = YES;
        self.fiveStartButton.hidden = YES;
        self.twoStartButton.selected = NO;
        self.threeStartButton.selected = NO;
        self.fourStartButton.selected = NO;
        self.fiveStartButton.selected = NO;
        self.subtractButton.x = 108 * SCREENH6;
        self.addButton.x = 138 * SCREENH6;
    }else if (addCount == 2){
        
        self.addButton.hidden = NO;
        self.twoStartButton.hidden = NO;
        self.threeStartButton.hidden = YES;
        self.fourStartButton.hidden = YES;
        self.fiveStartButton.hidden = YES;
        self.threeStartButton.selected = NO;
        self.fourStartButton.selected = NO;
        self.fiveStartButton.selected = NO;
        self.subtractButton.x = 108 * SCREENH6 + 50 * SCREENH6 * (addCount - 1);
        self.addButton.x = 138 * SCREENH6 + 50 * SCREENH6 * (addCount - 1);
    }else if (addCount == 3){
        
        self.addButton.hidden = NO;
        self.twoStartButton.hidden = NO;
        self.threeStartButton.hidden = NO;
        self.fourStartButton.hidden = YES;
        self.fiveStartButton.hidden = YES;
        self.fourStartButton.selected = NO;
        self.fiveStartButton.selected = NO;
        self.subtractButton.x = 108 * SCREENH6 +50 * SCREENH6 * (addCount - 1);
        self.addButton.x = 138 * SCREENH6 + 50 * SCREENH6 * (addCount - 1);
    }else if (addCount == 4){
        
        self.addButton.hidden = NO;
        self.twoStartButton.hidden = NO;
        self.threeStartButton.hidden = NO;
        self.fourStartButton.hidden = NO;
        self.fiveStartButton.hidden = YES;
        self.fiveStartButton.selected = NO;
//        self.addButton.hidden = YES;
        self.subtractButton.x = 108 * SCREENH6 +50 * SCREENH6 * (addCount - 1);
        self.addButton.x = 138 * SCREENH6 + 50 * SCREENH6 * (addCount - 1);
    }else if (addCount == 5){
        
        self.twoStartButton.hidden = NO;
        self.threeStartButton.hidden = NO;
        self.fourStartButton.hidden = NO;
        self.fiveStartButton.hidden = NO;
        self.addButton.hidden = YES;
        self.subtractButton.x = 110 * SCREENH6 +50 * SCREENH6 * (addCount - 1);
    }
}

- (void)weekBtnClick:(UIButton *)button{
    
    button.selected = !button.selected;
    
}


- (void)clickChooseTimeButton:(UIButton *)button{
    
    if (button == self.normalTimeStartButton) {
        
        self.dateStr = @"normalTimeStart";
    }else if (button == self.normalTimeEndButton){
        
        self.dateStr = @"normalTimeEnd";
    }else if (button == self.normalDateStartButton){

        self.dateStr = @"normalDateStart";
    }
    else if (button == self.normalDateEndButton){
        
        self.dateStr = @"normalDateEnd";
    }else if (button == self.oneStartButton){
        
        self.dateStr = @"oneStart";
    }else if (button == self.twoStartButton){
        
        self.dateStr = @"twoStart";
    }else if (button == self.threeStartButton){
        
        self.dateStr = @"threeStart";
    }else if (button == self.fourStartButton){
        
        self.dateStr = @"fourStart";
    }else if (button == self.fiveStartButton){
        
        self.dateStr = @"fiveStart";
    }
    
    [self presentDateController];
}


- (void)clickChooseModelButton:(UIButton *)button{
    
    if (button == self.normalButton) {

        if (!button.selected) {

            button.selected = YES;
            self.exploreImageView.hidden = YES;
            self.tuanButton.selected = NO;

            self.modeView.height = 125 * SCREENH6;
            self.tuanView.hidden = YES;
            self.normalView.hidden = NO;
        }
    }else{

        if (!button.selected) {

            button.selected = YES;
            self.exploreImageView.hidden = NO;
            self.normalButton.selected = NO;
            self.modeView.height = 235 * SCREENH6;
            self.tuanView.hidden = NO;
            self.normalView.hidden = YES;
        }
    }
}

- (void)presentDateController{
    
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.datePickerType = PGDatePickerType1;
    datePicker.isHiddenMiddleText = false;
    if ([self.dateStr isEqualToString:@"normalDateStart"] || [self.dateStr isEqualToString:@"normalDateEnd"]) {
        
        datePicker.datePickerMode = PGDatePickerModeDateHourMinuteSecond;
    }else{
        
        datePicker.datePickerMode = PGDatePickerModeTime;
    }
    
    //    datePicker.maximumDate = [NSDate date];
    datePicker.language = @"zh-Hans";
    [self presentViewController:datePickManager animated:false completion:nil];
}


#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    
    
    if ([self.dateStr isEqualToString:@"normalDateStart"] || [self.dateStr isEqualToString:@"normalDateEnd"]) {
        
        NSString * date = [NSString stringWithFormat:@"%li-%02li-%02li %02li:%02li:%02li",(long)dateComponents.year,(long)dateComponents.month,(long)dateComponents.day,(long)dateComponents.hour,(long)dateComponents.minute,(long)dateComponents.second];
        
        if ([self.dateStr isEqualToString:@"normalDateStart"]) {
            
            [self.normalDateStartButton setTitle:date forState:UIControlStateNormal];
            self.normalDateStartButton.selected = YES;
            self.normalDateStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else{
           
            [self.normalDateEndButton setTitle:date forState:UIControlStateNormal];
            self.normalDateEndButton.selected = YES;
            self.normalDateEndButton.layer.borderColor = [ZRBlackColor CGColor];
        }
    }else{
        
        NSString * date = [NSString stringWithFormat:@"%02li:%02li",(long)dateComponents.hour,(long)dateComponents.minute];
        
        if ([self.dateStr isEqualToString:@"normalTimeStart"]) {
            
            [self.normalTimeStartButton setTitle:date forState:UIControlStateNormal];
            self.normalTimeStartButton.selected = YES;
            self.normalTimeStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"normalTimeEnd"]) {
            
            [self.normalTimeEndButton setTitle:date forState:UIControlStateNormal];
            self.normalTimeEndButton.selected = YES;
            self.normalTimeEndButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"oneStart"]) {
            
            [self.oneStartButton setTitle:date forState:UIControlStateNormal];
            self.oneStartButton.selected = YES;
            self.oneStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"twoStart"]) {
            
            [self.twoStartButton setTitle:date forState:UIControlStateNormal];
            self.twoStartButton.selected = YES;
            self.twoStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"threeStart"]) {
            
            [self.threeStartButton setTitle:date forState:UIControlStateNormal];
            self.threeStartButton.selected = YES;
            self.threeStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"fourStart"]) {
            
            [self.fourStartButton setTitle:date forState:UIControlStateNormal];
            self.fourStartButton.selected = YES;
            self.fourStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }else if ([self.dateStr isEqualToString:@"fiveStart"]) {
            
            [self.fiveStartButton setTitle:date forState:UIControlStateNormal];
            self.fiveStartButton.selected = YES;
            self.fiveStartButton.layer.borderColor = [ZRBlackColor CGColor];
        }
    }
    
}

- (void)didNavButton:(UIButton *)button{
    
    NSString *html = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('content').innerHTML"];
    NSString *script = [self.webView stringByEvaluatingJavaScriptFromString:@"window.alertHtml()"];
    [self.webView stringByEvaluatingJavaScriptFromString:script];

        //对输出的富文本进行处理后上传
//  NSLog(@"[self changeString:html]==%@",html);
    NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
    NSString *encodeScript = [html stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
        
        if (self.normalButton.selected) {
            //普通模式
//            NSArray *subviews = [self.normalWeekView subviews];
//            // 如果没有子视图就直接返回
//            if ([subviews count] == 0){
//
//                return;
//            }
//
//            NSMutableArray * muArr = [NSMutableArray array];
//
//            for (WeekButton *button in subviews) {
//
//                if (button.selected) {
//
//                    [muArr addObject:button.titleLabel.text];
//                }
//            }

//            NSString * weekStr = [muArr componentsJoinedByString:@","];
            NSString * weekStr;
            if (self.workButton.selected) {

                weekStr = self.workButton.titleLabel.text;
            }else if (self.weekendsButton.selected){

                weekStr = self.weekendsButton.titleLabel.text;
            }else if (self.everydayButton.selected){

                weekStr = self.everydayButton.titleLabel.text;
            }

            NSString * merchants_img;
            if (self.imgArray.count > 0) {

                merchants_img = [self.imgArray componentsJoinedByString:@","];
            }else{

                merchants_img = @"";
            }

            if (self.titleTextField.text.length > 0 && self.priceTextField.text.length > 0 && self.orignTextField.text.length > 0 && self.localButton.selected && self.repertoryTextfield.text.length > 0 && self.normalDateEndButton.selected && self.normalDateStartButton.selected) {

                ShowHUD;
                NSString * timeStr = [NSString stringWithFormat:@"%@ %@-%@",weekStr,self.normalTimeStartButton.titleLabel.text,self.normalTimeEndButton.titleLabel.text];
                if (self.ID) {

                    NSDictionary * dict = @{@"merchants_goods_name":self.titleTextField.text,@"merchants_goods_price":self.orignTextField.text,@"merchants_goods_category":self.typeid,@"merchants_goods_discount_price":self.priceTextField.text,@"merchants_goods_inventory":self.repertoryTextfield.text,@"merchants_goods_end_time":self.normalDateEndButton.titleLabel.text,@"merchants_goods_type":@"1",@"merchants_goods_available_time":timeStr,@"merchants_goods_img":merchants_img,@"merchants_goods_info":encodeScript,@"id":self.ID,@"merchants_goods_start_time":self.normalDateStartButton.titleLabel.text};

                    [[ZRNetworkTool sharedTool] editMerchantsGoodsResultWithDict:dict WithBlock:^(BOOL success, id responseData) {
                        HiddenHUD;
                        if (success) {

                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:@"恭喜你修改成功！"
                                                                                    preferredStyle:UIAlertControllerStyleAlert];

                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                                  }];

                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }else{

                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:responseData[@"message"]
                                                                                    preferredStyle:UIAlertControllerStyleAlert];

                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {

                                                                                  }];

                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }
                    }];

                }else{

                    NSDictionary * dict = @{@"merchants_goods_name":self.titleTextField.text,@"merchants_goods_price":self.orignTextField.text,@"merchants_goods_category":self.typeid,@"merchants_goods_discount_price":self.priceTextField.text,@"merchants_goods_inventory":self.repertoryTextfield.text,@"merchants_goods_end_time":self.normalDateEndButton.titleLabel.text,@"merchants_goods_type":@"1",@"merchants_goods_available_time":timeStr,@"merchants_goods_img":merchants_img,@"merchants_goods_info":encodeScript,@"merchants_goods_start_time":self.normalDateStartButton.titleLabel.text};

                    [[ZRNetworkTool sharedTool] addMerchantsGoodsResultWithDict:dict WithBlock:^(BOOL success, id responseData) {
                        HiddenHUD;
                        if (success) {

                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:@"恭喜你发布成功！"
                                                                                    preferredStyle:UIAlertControllerStyleAlert];

                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                                  }];

                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }else{

                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:responseData[@"message"]
                                                                                    preferredStyle:UIAlertControllerStyleAlert];

                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {

                                                                                  }];

                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }
                    }];
                }

            }else{

                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:@"请先完善商品信息！"
                                                                        preferredStyle:UIAlertControllerStyleAlert];

                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {

                                                                      }];

                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }


        }else{
            //团购模式
            NSArray *subviews = [self.tuanWeekView subviews];
            // 如果没有子视图就直接返回
            if ([subviews count] == 0) return;
            
            NSMutableArray * muArr = [NSMutableArray array];
            
            for (WeekButton *button in subviews) {
                
                if (button.selected) {
                    NSString * str = [NSString stringWithFormat:@"%ld",(long)button.tag];
                    [muArr addObject:str];
                }
            }
            
            NSMutableArray * timeArr = [NSMutableArray array];
            
            if(self.oneStartButton.selected){
                
                [timeArr addObject:self.oneStartButton.titleLabel.text];
            }
            if(self.twoStartButton.selected){
                
                [timeArr addObject:self.twoStartButton.titleLabel.text];
            }
            if(self.threeStartButton.selected){
                
                [timeArr addObject:self.threeStartButton.titleLabel.text];
            }
            if(self.fourStartButton.selected){
                
                [timeArr addObject:self.fourStartButton.titleLabel.text];
            }
            if(self.fiveStartButton.selected){
                
                [timeArr addObject:self.fiveStartButton.titleLabel.text];
            }
            
            NSMutableDictionary * mudict = [NSMutableDictionary dictionary];
            
            for (NSString * key in muArr) {
//                NSDictionary * dict = @{key:timeArr.copy};
                
                [mudict setValue:timeArr.copy forKey:key];
            }
            
            NSString * timeString = [self convertToJsonData:mudict.copy];
            NSCharacterSet *encodeUrlSeta = [NSCharacterSet URLQueryAllowedCharacterSet];
            NSString *encodeUrl = [timeString stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSeta];

            NSString * merchants_img;
            if (self.imgArray.count > 0) {
                
                merchants_img = [self.imgArray componentsJoinedByString:@","];
            }else{
                
                merchants_img = @"";
            }
            
            if (self.titleTextField.text.length > 0 && self.priceTextField.text.length > 0 && self.orignTextField.text.length > 0 && self.localButton.selected && self.stopTimeTextfield.text.length > 0 && self.minPeopleButton.text.length > 0 && self.maxPeopleButton.text.length > 0 && self.normalDateEndButton.selected && self.normalDateStartButton.selected) {
                ShowHUD;
                if(self.ID){
                    
                    NSDictionary * dict = @{@"merchants_goods_name":self.titleTextField.text,@"merchants_goods_price":self.orignTextField.text,@"merchants_goods_category":self.typeid,@"merchants_goods_discount_price":self.priceTextField.text,@"merchants_goods_type":@"2",@"merchants_goods_available_time":encodeUrl,@"merchants_goods_img":merchants_img,@"merchants_goods_info":encodeScript,@"merchants_goods_end_group_time":self.stopTimeTextfield.text,@"merchants_goods_min_pople":self.minPeopleButton.text,@"merchants_goods_max_pople":self.maxPeopleButton.text,@"merchants_goods_end_time":self.normalDateEndButton.titleLabel.text,@"id":self.ID,@"merchants_goods_start_time":self.normalDateStartButton.titleLabel.text,@"merchants_goods_cancel_order_time":self.cancleTimeTextfield.text};
                    
                    [[ZRNetworkTool sharedTool] editMerchantsGoodsResultWithDict:dict WithBlock:^(BOOL success, id responseData) {
                        HiddenHUD;
                        if (success) {
                            
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:@"恭喜你修改成功！"
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                                  }];
                            
                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }else{
                            
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:responseData[@"message"]
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      
                                                                                  }];
                            
                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }
                    }];
                    
                }else{
                   
                    NSDictionary * dict = @{@"merchants_goods_name":self.titleTextField.text,@"merchants_goods_price":self.orignTextField.text,@"merchants_goods_category":self.typeid,@"merchants_goods_discount_price":self.priceTextField.text,@"merchants_goods_type":@"2",@"merchants_goods_available_time":encodeUrl,@"merchants_goods_img":merchants_img,@"merchants_goods_info":encodeScript,@"merchants_goods_end_group_time":self.stopTimeTextfield.text,@"merchants_goods_min_pople":self.minPeopleButton.text,@"merchants_goods_max_pople":self.maxPeopleButton.text,@"merchants_goods_end_time":self.normalDateEndButton.titleLabel.text,@"merchants_goods_start_time":self.normalDateStartButton.titleLabel.text,@"merchants_goods_cancel_order_time":self.cancleTimeTextfield.text};
                    
                    [[ZRNetworkTool sharedTool] addMerchantsGoodsResultWithDict:dict WithBlock:^(BOOL success, id responseData) {
                        HiddenHUD;
                        if (success) {
                            
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:@"恭喜你发布成功！"
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                                  }];
                            
                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }else{
                            
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                           message:responseData[@"message"]
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                                  handler:^(UIAlertAction * action) {
                                                                                      
                                                                                  }];
                            
                            [alert addAction:defaultAction];
                            [self presentViewController:alert animated:YES completion:nil];
                        }
                    }];
                }

                
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:@"请先完善商品信息！"
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }
}



-(NSString *)convertToJsonData:(NSDictionary *)dict{
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        
        NSLog(@"%@",error);
        
    }else{
        
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        
    }
    
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
}

#pragma mark - Method
-(NSString *)changeString:(NSString *)str
{
    
    NSMutableArray * marr = [NSMutableArray arrayWithArray:[str componentsSeparatedByString:@"\""]];
    
    for (int i = 0; i < marr.count; i++)
    {
        NSString * subStr = marr[i];
        if ([subStr hasPrefix:@"/var"] || [subStr hasPrefix:@" id="])
        {
            [marr removeObject:subStr];
            i --;
        }
    }
    NSString * newStr = [marr componentsJoinedByString:@"\""];
    return newStr;
    
}

- (NSString *)stringFromDate:(NSDate *)date
{
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970];
    NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
    return timeString;
}


- (WeekButton *)setupWeekButtonWith:(NSString *)title{
    
    // 圆角按钮
    WeekButton * weekButton = [WeekButton new];

    [weekButton setTitle:title forState:UIControlStateNormal];
    [weekButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [weekButton setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [weekButton setImage:[UIImage imageNamed:@"圆角矩形6拷贝"] forState:UIControlStateNormal];
    [weekButton setImage:[UIImage imageNamed:@"绿色勾选"] forState:UIControlStateSelected];
    weekButton.titleLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    //按钮点击方法
    [weekButton addTarget:self action:@selector(clickNormalWeekButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.normalButtonArray addObject:weekButton];
    
    return weekButton;
}


- (void)clickNormalWeekButton:(UIButton *)button{
    
    if (button == self.workButton) {
        
        if (!button.selected) {
            
            button.selected = YES;
            
            self.weekendsButton.selected = NO;
            self.everydayButton.selected = NO;
        }
    }else if (button == self.weekendsButton){
        
        if (!button.selected) {
            
            button.selected = YES;
            
            self.workButton.selected = NO;
            self.everydayButton.selected = NO;
        }
    }else if (button == self.everydayButton){
        
        if (!button.selected) {
            
            button.selected = YES;
            
            self.workButton.selected = NO;
            self.weekendsButton.selected = NO;
        }
        
    }
}

@end
